package com.sixfoot.domain;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sixfoot.foundation.persistence.UUIDBaseModel;

@Entity
@Table(name = "organization")
public class Organization extends UUIDBaseModel {
	/**
	 * 部门名称
	 */
	private String name;
	/**
	 * 部门描述
	 */
	private String remark;
	/** 
	 * 部门角色 
	 * */
	private Set<OrganizationRolePermissions> roles;
	/**
	 * 部门用户
	 */
	private Set<User> users;
	
	private Organization parent;
//	@JsonIgnore
	private Set<Organization> children;
	private int seq;// 用于菜单排序
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	@OneToMany(mappedBy = "organization", fetch=FetchType.LAZY)
	@JsonIgnore
	public Set<User> getUsers() {
		return users;
	}
	public void setUsers(Set<User> users) {
		this.users = users;
	}
	@ManyToOne
	public Organization getParent() {
		return parent;
	}
	@JsonBackReference
	public void setParent(Organization parent) {
		this.parent = parent;
	}
	@OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
	@OrderBy("seq")
	public Set<Organization> getChildren() {
		return children;
	}
	public void setChildren(Set<Organization> children) {
		this.children = children;
	}
	public int getSeq() {
		return seq;
	}
	public void setSeq(int seq) {
		this.seq = seq;
	}
	@OneToMany(mappedBy = "organization", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JsonIgnore
	public Set<OrganizationRolePermissions> getRoles() {
		return roles;
	}
	public void setRoles(Set<OrganizationRolePermissions> roles) {
		this.roles = roles;
	}
}
